/**
 * create by young (young2f@outlook.com) on 2020/12/4
 * 库存批准记录
 */
'use strict';
const model = require('../base/modelBase');
const _ = require('lodash');
module.exports = app => {
  const mongoose = app.mongoose;
  const schema = mongoose.Schema;
  const connect = app.mongooseDB.get('pmcBus');
  const json = {
    lotType: {
      type: 'string', _type: 'string', title: '入库类型', enableArea: []
    },
    name: {
      type: 'string', _type: 'search', table: 'material', title: '物料名称', required: true, enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    code: {
      type: 'string', _type: 'search', table: 'material', title: '物料编码', required: true, enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    pmLotId: {
      type: 'string', _type: 'string',title: '物料采购批次编码', required: true, enableArea: [

      ]
    },
    lotCode: {
      type: 'string', _type: 'string',title: '批次编码', required: true, enableArea: [

      ]
    },
    procureOrderCode: {
      type: 'string', _type: 'string', table: 'material', title: '采购单编码', required: true, disabled: true, enableArea: [
        'table',
        'detail',
        'search'
      ]
    },
    price: {
      type: 'number', _type: 'number', title: '含17单价', enableArea: [
        'table', 'input',
        'detail',
      ], default: 0
    },

    // materialBody: {
    //   type: 'object', _type: 'object', table: 'material', title: '物料信息', required: true, enableArea: []
    // },
    vendor: {
      type: 'string', _type: 'string', title: '供应商名称', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    vendorCode: {
      type: 'string', _type: 'string', title: '供应商编码', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    subcategory: {
      type: 'string', _type: 'string', title: '小类', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    spec: {
      type: 'string', _type: 'string', title: '规格', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    number: {
      type: 'string', _type: 'string', title: '物料编号', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    type: {
      type: 'string', _type: 'string', title: '物料类型', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    count: {
      type: Number, _type: 'number', title: '采购数量', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    checkInfo: {
      type: 'object', _type: 'object', table: 'material', title: '检查信息', required: true, enableArea: []
    },

    inboundCount: {
      type: Number, _type: 'number', title: '入库数量', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    inboundDate: {
      type: Date, _type: 'date', title: '入库日期', enableArea: [
        'table',
        'detail',
        'search'
      ]
    },
    fileList: {
      type: Array, _type: 'array', title: '附件', enableArea: [

      ]
    },

  };
  const _model = _.cloneDeep(model);
  _.assign(_model, json);
  const _schema = new schema(
    _model,
    { timestamps: { createdAt: 'createdTs', updatedAt: 'updatedTs' } }
  );
  return connect.model('InboundLot', _schema);
};
